home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / kowin / archive / net / koprosrc.lzh / send.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-30  |  2.7 KB  |  157 lines

  1. /*    Copyright 1992 H.Ogasawara(COR.)    */
  2.  
  3. #include    "proto.h"
  4. #include    "run.h"
  5.  
  6. /*
  7.     X-MODEM128
  8.     X-MODEM1024
  9.     Y-MODEM
  10.     Y-MODEM-batch
  11. */
  12.  
  13. #define    GWAIT    8    /*(20*100)    /*8*/
  14.  
  15. unsigned short    top= 0,
  16.         blockn= 0;
  17.  
  18. WritePack( pack, len )
  19. unsigned char    *pack;
  20. {
  21.     while( len-- ){
  22.         if( Write232C( *pack++ ) < 0 )
  23.             return    -1;
  24.     }
  25.     return    0;
  26. }
  27.  
  28. SendEnd()
  29. {
  30.     EndProgram();
  31. }
  32.  
  33. void
  34. SendRun2( ptr )
  35. unsigned char    *ptr;
  36. {
  37.     if( ptr && *ptr == ACK ){
  38.         CloseFile();
  39.         timeout= runsize= 0;
  40.         SendEnd();
  41.         return;
  42.     }
  43.     Write232C( CAN );
  44.     allbreak();
  45. }
  46.  
  47. void
  48. SendRun1( ptr )
  49. unsigned char    *ptr;
  50. {
  51.     unsigned char    pack[2048],
  52.             buf[2048];
  53.     static int    len;
  54.     static unsigned short    chkmode= 0;
  55.     if( !ptr ){
  56.         if( chkmode == __G ){
  57.             if( (len= ReadFile( buf, firstsize )) < 0 ){
  58.                 Write232C( EOT );
  59.                 run= SendRun2;
  60.                 goto    lasttime;
  61.             }
  62.             block+= len>>7;
  63.             size+= len;
  64.             len= DataPack( ++blockn & 0xff, pack, buf, chkmode == NAK ? len+0x8000 : len );
  65.             if( WritePack( pack, len ) < 0 ){
  66.                 allbreak();
  67.                 return;
  68.             }
  69.             DispCountup();
  70.             run= SendRun1;
  71.             timeout= GWAIT+ONTIME();
  72.             runsize= 0;
  73.         }else{
  74.             Write232C( CAN );
  75.             allbreak();
  76.         }
  77.     }else{
  78.         run= SendRun1;
  79.         if( top == 1 ){
  80.             if( (chkmode= *ptr) == NAK ){
  81.                 top= 0;
  82.                 goto    datasend;
  83.             }else if( *ptr == __C || *ptr == __G ){
  84.                 if( *ptr == __C && rettype < 2 ){
  85.                     top= 0;
  86.                     goto    datasend;
  87.                 }
  88.                 SetFilePacket( buf, fnamenode(filename), filesize, filetime );
  89.                 len= DataPack( 0, pack, buf, 128 );
  90.                 top= *ptr == __C ? 2 : 3;
  91.                 goto    writepack;
  92.             }else
  93.                 *ptr= CAN;
  94.         }else if( top == 3 ){
  95.             if( *ptr == __C || *ptr == __G ){
  96.                 top= 0;
  97.                 goto    datasend;
  98.             }else
  99.                 *ptr= CAN;
  100.         }else{
  101.             if( *ptr == NAK ){
  102.                 /* Error */
  103.             }else if( *ptr == ACK ){
  104.         datasend:
  105.                 if( top == 2 ){
  106.                     top= 3;
  107.                     goto    lasttime;
  108.                 }
  109.                 if( (len= ReadFile( buf, firstsize )) < 0 ){
  110.                     Write232C( EOT );
  111.                     run= SendRun2;
  112.                     goto    lasttime;
  113.                 }
  114.                 block+= len>>7;
  115.                 size+= len;
  116.                 len= DataPack( ++blockn & 0xff, pack, buf, chkmode == NAK ? len+0x8000 : len );
  117.                 DispCountup();
  118.             }else
  119.                 *ptr= CAN;
  120.         }
  121.         if( *ptr == CAN ){
  122.             Write232C( CAN );
  123.             allbreak();
  124.             return;
  125.         }
  126.     writepack:
  127.         if( WritePack( pack, len ) < 0 ){
  128.             allbreak();
  129.             return;
  130.         }
  131.         if( top == 0 && chkmode == __G ){
  132.             timeout= GWAIT+ONTIME();;
  133.             runsize= 0;
  134.             return;
  135.         }
  136.     lasttime:
  137.         timeout= 6000+ONTIME();
  138.         runsize= 1;
  139.     }
  140. }
  141.  
  142. void
  143. SendStart()
  144. {
  145.     blockn= block= size= last= 0;
  146.     if( OpenFileR( filename ) < 0 )
  147.         return;
  148.     run= SendRun1;
  149.     top= 1;
  150.     firstsize= rettype == 0 ? 128 : 1024;
  151.     timeout= 6000+ONTIME();
  152.     while( ISNS232C() )
  153.         INP232C();
  154.     runsize= 1;
  155. }
  156.  
  157.